package com.fs.system.teacher.controller;

import com.fs.system.common.ResponseData;
import com.fs.system.student.domain.ApplicationRecord;
import com.fs.system.teacher.domain.First;
import com.fs.system.teacher.domain.Teacher;
import com.fs.system.teacher.mapper.TeacherMapper;
import com.fs.system.teacher.service.TeacherService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.fs.system.common.ResultEnums.*;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    TeacherService teacherService;

    /**
     * 教师修改个人信息
     */
    @PutMapping("/update")
    public ResponseData updateTeacher(@RequestBody Teacher teacher){
        teacherService.update(teacher);
        return new ResponseData("200","更新成功");
    }

    /**
     * 教师获取待审核的数据
     */
//    @GetMapping("/selectFirst")
//    public ResponseData selectFirst(@RequestParam Long teaId){
//        teacherService.selectFirst(teaId);
//    }

    /**
     * 院长管理员添加单个教师信息
     * 默认字段：password，role，status，isDeleted,title
     * 必须有的字段：username,password,realname,title,college_id,status,role,isDeleted,create_by,create_time.
     */
    @PostMapping("/adminAddOneTeacher")
    public ResponseData addOneTeacher(@RequestBody Teacher teacher){
        teacherService.addOneTeacher(teacher);
        return new ResponseData("200","新增成功");
    }

    /**
     * 院长管理员修改单个教师信息
     */
    @PutMapping("/adminModifyOneTeacher")
    public ResponseData modifyTeacherByAdmin(@RequestBody Teacher teacher){
        teacherService.modifyTeacher(teacher);
        return new ResponseData("200","修改成功");
    }

    /**
     * 院长管理员删除单个教师信息，实际为修改idDeleted
     * 需有：teaId,updateBy
     */
    @PutMapping("/adminDeleteTeacher")
    public ResponseData deleteTeacher(@RequestParam Long teaId, @RequestParam String updateBy){
        teacherService.deleteTeacher(teaId,updateBy);
        return new ResponseData("200","删除成功");
    }

    /**
     * 教师批量删除教师信息，
     */
//    @PutMapping("/adminDeleteManyTeacher")
//    public ResponseData deleteManyTeacher(@RequestParam("teaId")List<Integer> teaIds,@RequestParam("updateBy") String updateBy){
//
//    }

    /**
     * 查询教师列表
     */
    @GetMapping("/selectTeacher")
    public ResponseData selectTeacher(
            Teacher teacher,
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "5")Integer size){
        PageInfo<Teacher> list = teacherService.selectTeacher(teacher,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 查询所有教师列表
     */
    @GetMapping("/selectAllTeacher")
    public ResponseData selectAllTeacher(Teacher teacher){
        List<Teacher> list = teacherService.selectAllTeacher(teacher);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 根据id查询教师信息
     */
    @GetMapping("/selectById")
    public ResponseData selectById(Teacher teacher){
        Teacher teacher1 = teacherService.selectById(teacher);
        return new ResponseData("200","查询成功",teacher1);
    }

    /**
     * 教师获取待初审的信息
     * 根据老师id和状态查询
     * 查询的是最近一周的数据
     */
    @GetMapping("/getFirst")
    public ResponseData getFirst(ApplicationRecord applicationRecord,
                                 @RequestParam(defaultValue = "1")Integer page,
                                 @RequestParam(defaultValue = "5")Integer size){
        PageInfo<ApplicationRecord> list = teacherService.getFirst(applicationRecord,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 教师获取待初审的信息
     * 根据老师id和状态查询
     * 查询的是一周前的数据
     */
    @GetMapping("/getFirst2")
    public ResponseData getFirst2(ApplicationRecord applicationRecord,
                                  @RequestParam(defaultValue = "1")Integer page,
                                  @RequestParam(defaultValue = "5")Integer size){
        PageInfo<ApplicationRecord> list = teacherService.getFirst2(applicationRecord,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 教师初审材料
     */
    @PutMapping("/firstCheck")
    public ResponseData firstCheck(@RequestBody ApplicationRecord applicationRecord){
        teacherService.firstCheck(applicationRecord);
        return new ResponseData("200","修改成功");
    }

    /**
     * 教师通过初审时，添加一条初审记录
     */
    @PostMapping("/firstRecord")
    public ResponseData firstRecord(@RequestBody First first){
        teacherService.firstCord(first);
        return new ResponseData("200","添加成功");
    }

    /**
     * 教师获取审核记录列表
     */
    @GetMapping("/getRecord")
    public ResponseData getRecord(First first,
                                  @RequestParam(defaultValue = "1")Integer page,
                                  @RequestParam(defaultValue = "5")Integer size){
        PageInfo<First> list = teacherService.getRecord(first,page,size);
        return new ResponseData("200","查询成功",list);
    }

    /**
     * 根据记录id查询记录信息
     */
    @GetMapping("/getRecordById")
    public ResponseData getRecordById(First first,
                                  @RequestParam(defaultValue = "1")Integer page,
                                  @RequestParam(defaultValue = "5")Integer size){
        ApplicationRecord list = teacherService.getRecordById(first,page,size);
        return new ResponseData("200","查询成功",list);
    }


}
